const { isAccess, register, login, isHave, registers, logins } = require("../dao/userDao");


//出租方账号注册==============================================================
//验证账号是否存在
module.exports.isAccess = async function (account) {
    const data = await isAccess(account);
    if (data.length > 0) {
        return {
            status: true,
            data,
            message: '存在账号,不允许注册'
        }
    } else {
        return {
            status: false,
            data,
            message: '允许注册'
        }
    }
}
//注册
module.exports.register = async function (power) {
    //出租方注册
    const data = await register(power);
    if (data) {
        return {
            status: 1,
            data,
            message: '注册成功'
        }
    } else {
        return {
            status: 0,
            data,
            message: '注册失败'
        }
    }
}



module.exports.login = async function (power) {
    //出租方登录
    const data = await login(power);
    // console.log('得到的数据',data)
    if (data.length && data[0].state == '1') {
        return {
            status: 1,
            data,
            message: '登录成功'
        }
    } else {
        return {
            status: 0,
            data,
            message: '登录失败'
        }
    }

}

//验证租客账号是否注册
module.exports.isHave = async function (account) {
    const data = await isHave(account);
    if (data.length > 0) {
        return {
            status: true,
            data,
            message: '存在账号,不允许注册'
        }
    } else {
        return {
            status: false,
            data,
            message: '允许注册'
        }
    }
}

// 租客注册//注册
module.exports.registers = async function (power) {
    //出租方注册
    const data = await registers(power);
    if (data) {
        return {
            status: 1,
            data,
            message: '注册成功'
        }
    } else {
        return {
            status: 0,
            data,
            message: '注册失败'
        }
    }
}


// 登录
module.exports.logins = async function (power) {
    //出租方登录
    const data = await logins(power);
    // console.log('得到的数据',data)
    if (data.length) {
        return {
            status: 1,
            data,
            message: '登录成功'
        }
    } else {
        return {
            status: 0,
            data,
            message: '登录失败'
        }
    }

}